import 'package:flutter/cupertino.dart';

import 'Dazzle.dart';

class ItemToList {
  final List<Item> items;
  var _map = <String, Item>{};
  ItemToList(this.items) {
    for (Item item in items) {
      _map[item.type] = item;
    }
  }

  Widget conver(BuildContext context, int index,dynamic data) {
    return _getWidget(context, index,data);
  }

  Widget _getWidget(BuildContext context, int index,dynamic model) {
    if (model == null)
      return Container(
        child: Text("找不到相关控件"),
      );
    var item = _map[model.runtimeType.toString()];
    if (item == null)
      return Container(
        child: Text("找不到相关控件"),
      );
    return Container(
      height: item.mainPixel ?? null,
      width: double.infinity,
      margin: EdgeInsets.symmetric(vertical: item.mainAxisSpacing,horizontal: item.crossAxisSpacing),
      child: item.runItemBuild(context, index, model),
    );
  }
}
